import { createApp } from "vue";
import App from "./App.vue";
// reset style sheet
import "@/styles/reset.scss";


// vue-codemirror
import { basicSetup } from 'codemirror'
import VueCodemirror from 'vue-codemirror'


// Mdi css
// import "@mdi/font/scss/materialdesignicons.scss";
// iconfont css
import "@/assets/iconfont/iconfont.scss";
import "@/assets/iconfont/editor/iconfont.css";
// font css
import "@/assets/fonts/font.scss";
// element css
import "element-plus/dist/index.css";
// element dark css
import "element-plus/theme-chalk/dark/css-vars.css";
// custom element dark css
import "@/styles/element-dark.scss";
// custom element css
import "@/styles/element.scss";
// tag 签状态样式集合，主要用于 物流运输状态、关务状态、以及其他所有的状态集合，禁止因非状态因素修改此文件
import "@/styles/tag-status.scss";
// svg icons
import "virtual:svg-icons-register";
// CSS common style sheet
import "@/styles/common.scss";
// element plus
import ElementPlus from "element-plus";
// element icons
import * as Icons from "@element-plus/icons-vue";
//添加全局 的alert
import merakAlert from "@/components/merakAlert/index.vue";

import VueGridLayout from 'vue-grid-layout';
// vxe table
import VXETable from "vxe-table";
import VXEZhCN from "vxe-table/lib/locale/lang/zh-CN";
// custom directives
import directives from "@/directives/index";
// vue Router
import router from "@/routers";
// vue i18n
import I18n from "@/languages/index";
// pinia store
import pinia from "@/stores";
//图片查看
import VueViewer from 'v-viewer';
import 'viewerjs/dist/viewer.css';


// errorHandler
import errorHandler from "@/utils/errorHandler";
import { useGlobalStore } from "@/stores/modules/global";
import { LANGUAGE_MAP_KEY } from "@/config";

const app = createApp(App);

if (import.meta.env.DEV) {
  app.config.errorHandler = errorHandler;
}

// 注册全局过滤方法
import injectFliter from "@/utils/filters";
injectFliter(app);
// 挂载script中使用国际化语言

const t = I18n.global.t;
app.config.globalProperties.$t = t;

// vxe table 国际化
VXETable.config({
  i18n: (key, args) => I18n.global.t(key, args)
});

console.log(Icons);
// register the element Icons component
Object.keys(Icons).forEach(key => {
  app.component(key, Icons[key as keyof typeof Icons]);
});

//添加全局merakAlert组件
app.component("qf-alert", merakAlert);

//关闭i18n警告
I18n.global.fallbackWarn=false; 
I18n.global.missingWarn=false;

app.use(ElementPlus).use(VXETable).use(directives).use(router).use(I18n).use(pinia).use(VueGridLayout).use(VueCodemirror).mount("#app");

//根据当前语言加载翻译文件zz
const globalStore = useGlobalStore();
// import(/* @vite-ignore */ "https://sscn.tianxuan.work/language/global_" + globalStore.language + ".min.js?v="+LANGUAGE_MAP_KEY).then(arg => {
import(
  /* @vite-ignore */ "https://images-cn.tianxuan.link/merak/sync/business/language/global_" +
    globalStore.language +
    ".min.js?v=" +
    new Date().getTime()
).then(arg => {

  I18n.global.mergeLocaleMessage(globalStore.language!, { ...(arg.default ?? {}) });
  // vxe 国际化
  I18n.global.mergeLocaleMessage(globalStore.language!, {
    ...VXEZhCN,
    "vxe.table.sortAsc": t("merak.ascending_order"),
    "vxe.table.sortDesc": t("merak.descending_order")
  });
});
